<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">线片巷</label>
        <el-input v-model="query.linearId" clearable placeholder="线片巷" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <!-- <el-form-item label="id" prop="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item> -->
          <el-form-item label="线片巷" prop="linearName">
            <!-- 未设置字典，请手动设置 Select -->
            <div style="display:flex;">
              <el-input v-model="form.linearName" disabled />
              <el-button type="parimary" @click="lineVisible=true">选择</el-button>
            </div>
          </el-form-item>
          <!-- <el-form-item label="工作任务">
            <el-input v-model="form.workTasks" style="width: 370px;" />
          </el-form-item> -->
          <el-row>
            <el-col :span="24">
              <el-form-item label="帮扶单位">
                <div style="display:flex;">
                  <!-- <el-input v-model="form.taskName" disabled  /> -->
                  <div class="groupxzzy">
                    <el-tag v-for="item in form.assistanceUnit" :key="item.id" closable @close="handleClose(item)">
                      {{
                        item.name }}
                    </el-tag>
                  </div>
                  <el-button type="parimary" @click="multiple=true;deptVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="责任单位">
                <div style="display:flex;">
                  <el-input v-model="form.deptName" disabled />
                  <el-button type="parimary" @click="multiple=false;deptVisible=true">选择</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" tooltip-effect="dark" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="linearId" label="线片巷" width="355" show-overflow-tooltip="">
          <template slot-scope="scope">
            <div>{{ scope.row.linear.name }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="rpunit" label="责任单位">
          <template v-if="scope.row.rpunit!=null" slot-scope="scope">
            <div>{{ scope.row.rpunit.name }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="assistanceUnit" label="援助单位">
          <template slot-scope="scope">
            <div>{{ scope.row.assistanceUnit.map(i=>i.name).join('；') || '' }}</div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="workTasks" label="工作任务" /> -->
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="updateBy" label="最后修改人" />
        <el-table-column prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="更新时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','tLinearLaneTask:edit','tLinearLaneTask:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
    <SelecrGrop
      v-if="lineVisible"
      :dialog-visible.sync="lineVisible"
      title="选择线片港"
      @select="selectLine"
    />
    <selecrGropDept
      v-if="deptVisible"
      :dialog-visible.sync="deptVisible"
      title="选择单位"
      :multiple="multiple"
      :tag="tag"
      @select="selectDept"
    />
  </div>
</template>

<script>
import crudTLinearLaneTask from '@/api/system/tLinearLaneTask'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import SelecrGrop from './../components/selecrGroptLinearLane'
import selecrGropDept from './../components/selecrGropDept'
const defaultForm = { id: null, linearId: null, linearName: null, workTasks: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'TLinearLaneTask',
  components: { pagination, crudOperation, rrOperation, udOperation, SelecrGrop, selecrGropDept },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '线片巷单位任务管理', url: 'api/tLinearLaneTask', idField: 'id', sort: 'updateTime,desc', crudMethod: { ...crudTLinearLaneTask }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'tLinearLaneTask:add'],
        edit: ['admin', 'tLinearLaneTask:edit'],
        del: ['admin', 'tLinearLaneTask:del']
      },
      rules: {
        linearName: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'linearId', display_name: '线片巷' }
      ],
      lineVisible: false,
      deptVisible: false
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    selectLine(row) {
      this.lineVisible = false
      this.form.linearName = row.name
      this.form.linearId = row.id
      this.form.linear = row
    },
    // 选择单位
    selectDept(row) {
      this.deptVisible = false

      if (this.multiple) {
        // 组员
        this.form.assistanceUnit = row
      } else {
        // 组长
        this.form.rpunit = row
        this.form.deptName = row.name
      }
    },
    // 打开编辑弹窗前做的操作
    [CRUD.HOOK.beforeToEdit](crud, form) {
      this.form.linearName = form.linear && form.linear.name
      // this.form.taskName = form.task.workTasks
      this.form.deptName = form.rpunit && form.rpunit.name
      this.form.evaluationDtlName = form.evaluationDtl && form.evaluationDtl.name
      // this.form.souce = form.souce.toString()
      // this.form.uploadList = form.attachments.map(i => { i.url = process.env.VUE_APP_BASE_API + i.url; return i })
    }
  }
}
</script>
<style scoped>
.groupxzzy {
  border: 1px solid #c0c4cc;
  border-radius: 4px;
  min-height: 32px;
  padding: 5px 10px;
  width: 100%
}
</style>
